import Vue from 'vue'
import App from './App'
import store from './store'
import api from './utils/api.js'
import util from "./utils/util.js"
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'


Vue.use(ElementUI)

Vue.prototype.$api = api
Vue.prototype.$util = util
Vue.config.productionTip = false

App.mpType = 'app'
// #ifdef H5 
window.QQmap = null;
// #endif

// #ifndef MP-TOUTIAO
//网络监听
setTimeout(() => {
	uni.onNetworkStatusChange(function(res) {
		// console.log(res.networkType);
		store.commit("networkChange", {
			isConnected: res.isConnected
		})
	});
}, 100)
// #endif
Vue.prototype.$store = store

// android点击手机物理返回键退出app bug解决
document.addEventListener("plusready", function() {
	plus.key.addEventListener('backbutton', function() {
		window.history.go(-1);
	}, false);
}) 

// 阻止双击放大
window.onload = function() {
	let touchTime = 0;
	document.addEventListener('touchstart', function(event) {
	  if (event.touches.length > 1) {
	    event.preventDefault();
	  }
	});
	document.addEventListener('touchend', function(event) {
	  //记录当前点击的时间与下一次时间的间隔
	  var nowTime = new Date();    
	  if (nowTime.getTime()  - touchTime <= 300) {
	    event.preventDefault();
	  }
	  touchTime = nowTime.getTime();
	}, false);
};

const app = new Vue({
	store,
	...App
})

app.$mount()

Vue.component('remote-script', {
	render: function(createElement) {
		var self = this;
		return createElement('script', {
			attrs: {
				type: 'text/javascript',
				src: this.src
			},
			on: {
				load: function(event) {
					self.$emit('load', event);
				},
				error: function(event) {
					self.$emit('error', event);
				},
				readystatechange: function(event) {
					if (this.readyState == 'complete') {
						self.$emit('load', event);
					}
				}
			}
		});
	},
	props: {
		src: {
			type: String,
			required: true
		}
	}
});
